/*package com.jyb.qiyefuwu.view.fragment;

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputFilter;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.fastjson.JSONObject;
import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.bigkoo.pickerview.view.TimePickerView;
import com.google.android.material.tabs.TabLayout;
import com.jyb.qiyefuwu.R;
import com.jyb.qiyefuwu.databinding.FragmentEnterpriseBinding;
import com.jyb.qiyefuwu.entity.IpPickSelectEntity;
import com.jyb.qiyefuwu.router.PathHome;
import com.jyb.qiyefuwu.viewmodel.EnterpriseFragModel;
import com.jyb.qiyefuwu.viewmodel.ServiceTypeModel;
import com.swgk.core.base.AppLazyFragment;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.base.model.entity.MenuEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.refresh.SuperSwipeRefreshLayout;
import com.swgk.core.util.CheckUtils;
import com.swgk.core.util.DateUtils;
import com.swgk.core.util.MLog;
import com.swgk.core.util.MToast;
import com.swgk.core.util.PermissionUtils;
import com.swgk.core.util.SharedPreferenceUtil;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;


*//**
 * @author: 陈方凯
 * @date:   2021/09/15
 * @Description: 企业服务首页
 *//*
@Route(path = PathHome.EnterpriseServiceFragment)
public class EnterpriseServiceFragment  extends AppLazyFragment implements SuperSwipeRefreshLayout.OnPullRefreshListener {
    public EnterpriseFragModel mModel;
    private ServiceTypeModel mServiceTypeModel;
    private FragmentEnterpriseBinding mBind;
    //    private ReleaseCheckAdapter mCheckAdapter;
    private Intent intentService;
    private LinearLayoutManager mCheckAdapterManager;
    private ArrayList<Fragment> mFragments;
    private int mCurIndex;
    private TextView textView;
    private List<MenuEntity> listdata = new ArrayList<>();
    private boolean isLogin;
    private String phone;
    OptionsPickerView<IpPickSelectEntity> choice_type_options;//发票类型
    TimePickerView timePickerView;
    long mEndTime = 0;
    int demandType = -1;
    boolean getCode = false;


    public static EnterpriseServiceFragment newInstance() {
        EnterpriseServiceFragment fragment = new EnterpriseServiceFragment();
        Bundle bundle = new Bundle();
        fragment.setArguments(bundle);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mBind = DataBindingUtil.inflate(inflater, R.layout.fragment_enterprise, container, false);
        return mBind.getRoot();
    }

    @Override
    protected void setupFragmentComponent(AppComponent appComponent) {
        DaggerHomeFragComponent.builder()
                .appComponent(appComponent)
                .homeFragModule(new HomeFragModule(this))
                .build()
                .inject(this);
    }

    @Override
    protected void initView() {
        mBind.setViewModel(mModel);
        mServiceTypeModel = new ViewModelProvider(this).get(ServiceTypeModel.class);
        mBind.include.etPrice.addTextChangedListener(new DecimalInputTextWatcherMore(mBind.include.etPrice, 10, 2));
        mBind.include.etTitle.setFilters(new InputFilter[]{new NoSymbolputNewFilter()});
        mBind.include.etUsername.setFilters(new InputFilter[]{new NoSymbolputNewFilter()});
        EditTextUtils.setEditTextFlag(mBind.include.etTitle, null, 20);
        EditTextUtils.setEditTextFlag(mBind.include.etUsername, null, 10);
        // 刷新
        mBind.swipeRefresh.setOnPullRefreshListener(this);
        mBind.ivMapSearch.setOnClickListener(this);
        mBind.llMenuZhuanrang.setOnClickListener(this);
        mBind.llMenuFuwu.setOnClickListener(this);
        mBind.llMenuXuqiu.setOnClickListener(this);
        mBind.llMenuTuandui.setOnClickListener(this);
        mBind.include.linChoiceType.setOnClickListener(this);
        mBind.include.etNeedChoice.setOnClickListener(this);
        mBind.include.linChoicetime.setOnClickListener(this);
        mBind.include.textTime.setOnClickListener(this);
        mBind.include.imageDelete.setOnClickListener(this);
        mBind.appBarLayout.addOnOffsetChangedListener((appBarLayout, i) -> {
            if (i >= 0) {
                mBind.swipeRefresh.setEnabled(true);
            } else {
                mBind.swipeRefresh.setEnabled(false);
            }
        });
        mBind.swipeRefresh.setHeaderView(createHeaderView());
        mFragments = new ArrayList<>();
        getActivity().registerReceiver(mUpdateReceiver, updateIntentFilter());
        mServiceTypeModel.setCheckData();
        initObserver();
        initListener();


        Set<String> test = new TreeSet<String>();
        test.add("地方");
        test.add("士大夫");
        test.add("222");
        Log.e("set_string_log",test.add("222")+"");
        Log.e("set)string_list", JSONObject.toJSONString(test.toArray()));

    }

    @Override
    public void onResume() {
        super.onResume();
        initLoginData();
    }

    private void initLoginData() {
        //是否登录
        if (!TextUtils.isEmpty(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_TOKEN, ""))) {
            isLogin = true;
            mBind.include.etPhone.setText(
                    mServiceTypeModel.settingPhone(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_PHONE, ""))
            );
            mBind.include.tvCodeGet.setClickable(true);
            mBind.include.tvCodeGet.setTextColor(Color.parseColor("#5792FD"));
            mBind.include.etPhone.setFocusable(false);
            mBind.include.llCode.setVisibility(View.VISIBLE);
        } else {
            if (TextUtils.isEmpty(mBind.include.etPhone.getText().toString().trim())) {
                mBind.include.tvCodeGet.setClickable(false);
                mBind.include.tvCodeGet.setTextColor(Color.parseColor("#885792FD"));
            }
        }
    }

    *//**
     * 数据响应
     *//*
    private void initObserver() {
        //验证码
        mServiceTypeModel.VerificationCode.observe(this, s -> MToast.showToast(getActivity(), s));
        //服务发布
        mServiceTypeModel.publishDemand.observe(this, s -> {
            switch (s) {
                case "操作成功":
                    mBind.include.etTitle.setText("");
                    mBind.include.etCode.setText("");
                    mBind.include.etNeedChoice.setText("");
                    mBind.include.etPrice.setText("");
                    mBind.include.textTime.setText("");
                    mBind.include.etUsername.setText("");
                    mEndTime = 0;
                    mBind.include.tvCodeGet.setText("获取验证码");
                    mBind.include.textTime.setText("");
                    getCode = false;
                    mBind.include.imageDelete.setImageResource(R.mipmap.icon_expand);
//                    mBind.include.llCode.setVisibility(isLogin ? View.VISIBLE : View.GONE);
                    MToast.showToast(getActivity(), "您的需求已提交，正在为您匹配服务商！");
                    if (!isLogin) {
                        VerificationCodeLoginActivity.start(getActivity());
                        mBind.include.etPhone.setText("");
                    }
                    break;
                default:
                    MToast.showToast(getActivity(), s);
            }
        });
        mServiceTypeModel.ShowLoading.observe(this, integer -> {
            switch (integer) {
                case 1:
                    DialogHelper.showProgressDialog(getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
                    break;
                case 2:
                    DialogHelper.dismissProgressDialog();
                    break;
            }
        });
    }


    *//**
     * 初始化Listener
     *//*
    private void initListener() {


        mBind.include.etPhone.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (!isLogin)
                    if (!CheckUtils.isMobileNum_new(mBind.include.etPhone.getText().toString().trim())) {
                        mBind.include.tvCodeGet.setClickable(false);
                        mBind.include.tvCodeGet.setTextColor(Color.parseColor("#885792FD"));
                    } else {
                        mBind.include.tvCodeGet.setClickable(true);
                        mBind.include.tvCodeGet.setTextColor(Color.parseColor("#5792FD"));
                    }
            }
        });

        mBind.include.tvCodeGet.setOnClickListener(this);
        mBind.include.tvSubmit.setOnClickListener(this);
    }

    *//**
     * 防重点击事件
     *
     * @param v
     *//*
    @Override
    public void onMultiClick(View v) {
        super.onMultiClick(v);
        switch (v.getId()) {
            case R.id.tv_code_get:
                if(!getCode){
                    getCode = true;
                }
                intentService = new Intent(getActivity(), CodeTimerService.class);
                getActivity().startService(intentService);
                setPhone();
                mServiceTypeModel.getVerificationCode(phone);
                break;
            case R.id.tv_submit:
                if (TextUtils.isEmpty(mBind.include.etTitle.getText().toString().trim())) {
                    MToast.showToast(getActivity(), "请输入需求名称");
                    return;
                }

                if (TextUtils.isEmpty(mBind.include.etNeedChoice.getText().toString().trim())) {
                    MToast.showToast(getActivity(), "请选择需求分类");
                    return;
                }
//                if(TextUtils.isEmpty(mBind.include.etPrice.getText().toString().trim())){
//                    MToast.showToast(getActivity(), "请输入预算价格！");
//                    return;
//                }
//                if(TextUtils.isEmpty(mBind.include.textTime.getText().toString().trim())){
//                    MToast.showToast(getActivity(), "请选择需求最后办理期限！");
//                    return;
//                }

                if (TextUtils.isEmpty(mBind.include.etUsername.getText().toString().trim())) {
                    MToast.showToast(getActivity(), "请输入联系人姓名");
                    return;
                }


                if (!isLogin && TextUtils.isEmpty(mBind.include.etPhone.getText().toString().trim())) {
                    MToast.showToast(getActivity(), "请输入手机号");
                    return;
                }
                if (!isLogin && !CheckUtils.isMobileNum(mBind.include.etPhone.getText().toString().trim())) {
                    MToast.showToast(getActivity(), "请输入正确的电话格式");
                    return;
                }
                if (TextUtils.isEmpty(mBind.include.etCode.getText().toString().trim())) {
                    MToast.showToast(getActivity(), "请输入验证码");
                    return;
                }
                setPhone();
                mServiceTypeModel.publishDemandFun(
                        mBind.include.etTitle.getText().toString().trim()
                        , demandType
                        , TextUtils.isEmpty(mBind.include.etPrice.getText().toString().trim()) ? "" : mBind.include.etPrice.getText().toString().trim()
                        , mEndTime
                        , mBind.include.etUsername.getText().toString().trim()
                        , phone
                        , mBind.include.etCode.getText().toString().trim());
                break;
            case R.id.iv_map_search:
                if (PermissionUtils.checkPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION)) {//开启了定位权限
                    MapSearchServiceAcitivity.start(getContext());
                } else {
                    MToast.showToast(getContext(), "请完成位置授权");
                }
                break;
            case R.id.ll_menu_zhuanrang:
                ActivityJump.jumpToActivity(getActivity(), MakeOverActivity.class);
                break;
            case R.id.ll_menu_fuwu:
                ProfessionalQuoteActivity.start(getActivity());
                break;
            case R.id.ll_menu_xuqiu:
                NeedActivity.start(getActivity());
                break;
            case R.id.ll_menu_tuandui:
                ActivityJump.jumpToActivity(getActivity(), ProfessionalTeamChangeActivity.class);
                break;

            case R.id.et_need_choice:
            case R.id.lin_choice_type:
                KeyboardUtils.hideSoftInput(getActivity());
                if (choice_type_options == null) {
                    choice_type_options = new OptionsPickerBuilder(getActivity(), (options1, options2, options3, view) -> {
                        mBind.include.etNeedChoice.setText(mModel.getTypeData().get(options1).getName());
                        demandType = Integer.parseInt(mModel.getTypeData().get(options1).getId());
                    }).setCancelText("取消").setSubCalSize(15)
                            .setCancelColor(Color.parseColor("#666666"))
                            .setTitleColor(Color.parseColor("#969696")).setTitleSize(15)
                            .setSubmitText("确定")
                            .setSubmitColor(Color.parseColor("#5792FD"))
                            .setTextColorCenter(Color.parseColor("#ff333333"))
                            .setContentTextSize(15)
                            .setTitleText("选择分类")
                            .setLineSpacingMultiplier(2.5f)
                            .setDividerColor(Color.parseColor("#EDEDED"))
                            .build();
                    choice_type_options.setPicker(mModel.getTypeData());
                    choice_type_options.setSelectOptions(0);

                }
                choice_type_options.show();
                break;

            case R.id.lin_choicetime:
            case R.id.text_time:
                showchoiceTimeDialog();
                break;

            case R.id.image_delete:
                if (mEndTime > 0) {
                    mEndTime = 0;
                    mBind.include.textTime.setText("");
                    mBind.include.imageDelete.setImageResource(R.mipmap.icon_expand);
                } else {
                    showchoiceTimeDialog();
                }

                break;
        }
    }


    private void showchoiceTimeDialog() {
        KeyboardUtils.hideSoftInput(getActivity());
        if (timePickerView == null) {
            Calendar startDate = Calendar.getInstance();
            Calendar endDate = new GregorianCalendar();
            endDate.setTime(new Date(new BigDecimal(startDate.getTime().getTime()).add(new BigDecimal(31536000000L * 5)).add(new BigDecimal(86400000)).longValue()));
            timePickerView = PickerHelper.with(getContext()).getCommonTimeBuild("", new OnTimeSelectListener() {
                @Override
                public void onTimeSelect(Date date, View v) {

                    mEndTime = date.getTime();
                    mBind.include.textTime.setText(DateUtils.timestampToDate(date.getTime()));
                    mBind.include.imageDelete.setImageResource(R.mipmap.search_close);
                }
            }).setRangDate(startDate, endDate).setCancelText("取消").setSubCalSize(15)
                    .setCancelColor(Color.parseColor("#666666"))
                    .setTitleColor(Color.parseColor("#969696")).setTitleSize(15)
                    .setSubmitText("确定")
                    .setSubmitColor(Color.parseColor("#5792FD"))
                    .setTextColorCenter(Color.parseColor("#ff333333"))
                    .setContentTextSize(15)
                    .setTitleText("选择需求最后办理期限")
                    .setLineSpacingMultiplier(2.5f)
                    .setDividerColor(Color.parseColor("#EDEDED"))
                    .build();
        }
        timePickerView.show();
    }

    private void setPhone() {
        if (!isLogin) {
            phone = mBind.include.etPhone.getText().toString();
        } else {
            phone = SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_PHONE, "");
        }
    }

    // 注册广播
    private static IntentFilter updateIntentFilter() {
        final IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(CodeTimerService.IN_RUNNING);
        intentFilter.addAction(CodeTimerService.END_RUNNING);
        return intentFilter;
    }

    // 广播接收者
    private final BroadcastReceiver mUpdateReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            final String action = intent.getAction();
            switch (action) {
                case CodeTimerService.IN_RUNNING:
                    if (mBind.include.tvCodeGet.isEnabled())
                        mBind.include.tvCodeGet.setEnabled(false);
                    // 正在倒计时
//                    mBind.include.tvCodeGet.setTextColor(Color.GRAY);
                    mBind.include.tvCodeGet.setText(intent.getStringExtra("time") + "秒后重新发送");

                    break;
                case CodeTimerService.END_RUNNING:
                    // 完成倒计时
//                    mBind.include.tvCodeGet.setTextColor(getResources().getColor(R.color.new_blue));
                    mBind.include.tvCodeGet.setEnabled(true);
                    mBind.include.tvCodeGet.setText(getCode?"重新获取验证码":"获取验证码");
                    getCode = false;
                    break;
            }
        }
    };

    private void updateTvcodeGet(){

    }

    private TextView selectTextView;

    private void initTab() {

        mBind.tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                mCurIndex = tab.getPosition();
                if (selectTextView == null)
                    selectTextView = new TextView(getActivity());
                selectTextView.setTextSize(15);
                selectTextView.setTextColor(getResources().getColor(R.color.color_main));
                selectTextView.setText(tab.getText());
                selectTextView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                tab.setCustomView(selectTextView);
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
                tab.setCustomView(null);
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }


    public void initTopMenu(final List<ServiceSecondClassEntiy> mdatas) {

        listdata.clear();
        for (ServiceSecondClassEntiy mdata : mdatas) {
            MenuEntity menuEntity = new MenuEntity();

            menuEntity.setName(mdata.getService_class());
            menuEntity.setRealname(mdata.getService_class());
            menuEntity.setId(mdata.getId() + "");
            //字符太长
            if (menuEntity.getName().length() > 6) {
                String name = menuEntity.getName().substring(0, 5) + "...";
                menuEntity.setName(name);
            } else {
                menuEntity.setName(menuEntity.getName());
            }
            menuEntity.setAppIcon(mdata.getService_icon());
            listdata.add(menuEntity);
        }

        mBind.calendarMenuView.initData(getChildFragmentManager(), listdata, new CountMenuView.OnItemClick() {
            @Override
            public void onItemClick(MenuEntity entity, int position, int num) {

                ServiceTypeActivity.start(getActivity(), entity.getId() + "", entity.getRealname());
            }
        });

    }

    @Override
    protected void onLazyLoad() {
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }
        // 顶部分类
//        initTopMenu();
        mModel.getServerTitleLable();
        initTab();
        updateViews();
    }

    private void refreshView() {
        if (mFragments == null || mFragments.size() == 0) {
            hideRefresh();
            onLazyLoad();
            return;
        }
        mModel.getServerTitleLable();
        Fragment fragment = mFragments.get(mCurIndex);
        if (fragment instanceof EnterpriseItemFragment) {
            ((EnterpriseItemFragment) fragment).onLazyLoad();
        }
        hideRefresh();
    }

    public void hideRefresh() {
        mBind.swipeRefresh.setRefreshing(false);
    }

    public void showEmpty() {
        hideRefresh();
    }

    public void updateViews() {
        String[] mTitles = {"最新需求", "精品商标", "热门版权", "优质专利", "专业服务", "专业团队"};
        mFragments = new ArrayList<>();
        for (int i = 0; i < mTitles.length; i++) {
            mFragments.add(EnterpriseItemFragment.newInstance(i));
        }
        CommPagerAdapter mPagerAdapter = new CommPagerAdapter(getChildFragmentManager(), mFragments, mTitles);

//        mBind.viewPager.setOffscreenPageLimit(mTitles.length);
        mBind.viewPager.setAdapter(mPagerAdapter);
        mBind.tabLayout.setupWithViewPager(mBind.viewPager);
        mBind.tabLayout.getTabAt(0).select();
//        mBind.tabLayout.setTabMode(mFragments.size() > 3 ? TabLayout.MODE_SCROLLABLE : TabLayout.MODE_FIXED);
    }


    private View createHeaderView() {
        @SuppressLint("InflateParams")
        View headerView = LayoutInflater.from(mBind.swipeRefresh.getContext()).inflate(R.layout.super_swipe_refresh_head, null);
        ProgressBar progressBar = headerView.findViewById(R.id.pb_view);
        textView = headerView.findViewById(R.id.text_view);
        textView.setText("下拉刷新");
        progressBar.setVisibility(View.GONE);
        return headerView;
    }

    @Override
    public void onRefresh() {
        textView.setText("正在刷新");
        refreshView();
    }

    @Override
    public void onPullDistance(int distance) {

    }

    @Override
    public void onPullEnable(boolean enable) {
        textView.setText(enable ? "释放立即刷新" : "下拉刷新");
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEvent(MenuEvent event) {
        if (event.getMessageTag() == EventConstant.EVENT_MENU_POWER) {
            MLog.d("api", event.getNo());
            PowerListActivity.start(getActivity(), event.getNo(), event.getChildNo());
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEvent(LoginEvent event) {
        if (event.getMessageTag() == EventConstant.EVENT_LOGIN_OUT) {
            isLogin = false;
            mBind.include.etPhone.setText("");
            mBind.include.etTitle.setText("");
            mBind.include.etCode.setText("");
            mBind.include.etNeedChoice.setText("");
            mBind.include.etPrice.setText("");
            mBind.include.textTime.setText("");
            mBind.include.etUsername.setText("");
            mBind.include.tvCodeGet.setClickable(false);
            mEndTime = 0;
            mBind.include.textTime.setText("");
            mBind.include.imageDelete.setImageResource(R.mipmap.icon_expand);
            mBind.include.tvCodeGet.setTextColor(Color.parseColor("#885792FD"));
            mBind.include.etPhone.setFocusable(true);
            mBind.include.etPhone.setFocusableInTouchMode(true);
        }
    }

    @Override
    public void onDestroy() {
        EventBus.getDefault().unregister(this);
        super.onDestroy();
    }
}
}*/
